package com.mison.action;



import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.mison.core.Action;
import com.mison.core.FrameworkFather;
import com.mison.core.Result;
import com.mison.dao.GuostDao;
import com.mison.model.MisonFeedback;
import com.mison.model.MisonFeedbackPerson;
import com.mison.model.MisonStudent;

import com.mison.utils.Page;

public class GuostAction extends FrameworkFather {

	
    private Page<MisonFeedback> page = new Page<MisonFeedback>(3);;
    private List<MisonFeedback> list;
    private String content=""; 
	private int to_id;
    private int m_pid;
    private int m_fid;
    private int m_sid;
    private String m_c;

    
    public int getM_pid() {
		return m_pid;
	}


	public void setM_pid(String mPid) {
		m_pid = Integer.parseInt(mPid);
	}


	public int getM_fid() {
		return m_fid;
	}


	public void setM_fid(String mfid) {
		m_fid = Integer.parseInt(mfid);
	}


	public int getM_sid() {
		return m_sid;
	}


	public void setM_sid(String mSid) {
		m_sid = Integer.parseInt(mSid);
	}


	public String getM_c() {
		return m_c;
	}


	public void setM_c(String mC) {
		m_c = mC;
	}


    
    
    
	public int getTo_id() {
		return to_id;
	}


	public void setTo_id(String to_id) {
		this.to_id = Integer.parseInt(to_id);
	}


	@Override
	
	public Result execute(HttpServletRequest request,
			HttpServletResponse response, Action action) {
		
		GuostDao dao = new GuostDao();
		
		
		list = new ArrayList<MisonFeedback>();
        int total = dao.getCount(content);
		
		page.setTotalCount(total);
		
		page.setMaxPage((int)Math.ceil((double)total/page.getPerPage()));
		
		list = dao.getList(page, content);
		page.setList(list);
		System.out.println("execute-------"+to_id);
		return action.getResult("r1");
		
		
	}
	
	
	public  Result edit(HttpServletRequest request,
			HttpServletResponse response, Action action){
		
		System.out.println("edit-------"+to_id);
		
        GuostDao dao = new GuostDao();
		list = new ArrayList<MisonFeedback>();
        
		list = dao.getSelectList(page, to_id);
		page.setList(list);

		return action.getResult("r2");
		
		
	}
	public  Result update(HttpServletRequest request,
			HttpServletResponse response, Action action){
		
		System.out.println("update-------"+to_id);
		
        GuostDao dao = new GuostDao();
        MisonFeedback mf = new MisonFeedback();
        MisonFeedbackPerson mp = new MisonFeedbackPerson();
        MisonStudent ms = new MisonStudent();
        mf.setFeedbackId(m_fid);
        mf.setContent(m_c);
        mf.setMisonFeedbackPerson(mp);
        mf.setMisonStudent(ms);
        ms.setStudentId(m_sid);
        mp.setFeedbackPersonId(m_pid);
		dao.updateSelectList(mf, to_id);
		
		return execute(request, response, action);
		

		
		
		
	}
	public  Result delete(HttpServletRequest request,
			HttpServletResponse response, Action action){
		
		System.out.println("delete-------"+to_id);
		
        GuostDao dao = new GuostDao();
		
        
		dao.getDeleteList(to_id);
		return execute(request, response, action);
		
		
	}
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public List<MisonFeedback> getList() {
		return list;
	}
	public void setList(List<MisonFeedback> list) {
		this.list = list;
	}
	public Page<MisonFeedback> getPage() {
		return page;
	}
	public void setPage(Page<MisonFeedback> page) {
		this.page = page;
	}
	
	public void setCurrPage(String currPage) {
		page.setCurrPage(Integer.parseInt(currPage));
	}
//	public String getString_content(){
//		return null;
//	}
//	public void setString_content(String m_c){
//		m_c.substring(1, 10);
//	}
//	public String substring(String m_c){
//		return m_c.substring(1, 10);
//		
//	}

}
